package com.vates.login.webapp.beans;

import java.io.IOException;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.vates.login.model.User;
import com.vates.login.services.UserService;

@ManagedBean
@SessionScoped
@Component
public class UserBean {
	
	@Autowired
	private UserService userService;
	
	private User user = new User();

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	public String doSave() {
		user.setIsActive(true);
		userService.save(user);
		return "";
	}
	
	public String editUser(String userId) throws IOException {
		user = userService.get(new Long(userId));
		FacesContext.getCurrentInstance().getExternalContext().redirect("faces/userEdit.xhtml");
		return "";
	}
}
